home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: ZStringParser.h
-
- Contains: Class for parsing named ZStrings into platform-
- specific strings.
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #ifndef __ZSTRINGPARSER__
- #define __ZSTRINGPARSER__
-
-
- #include "ZStringData.h"
- #include <cstdio>
-
- typedef Z_UInt16 ZStringTagID;
-
- // WARNING: If you add to the following enumeration,
- // you may need to visit all the platform-specific
- // parsing routines (GetTagReplacement methods).
- enum
- {
- kZTag_Invalid = 0,
- kZTag_AElig,
- kZTag_Aacute,
- kZTag_Acirc,
- kZTag_Agrave,
- kZTag_Aring,
- kZTag_Atilde,
- kZTag_Auml,
- kZTag_Ccedil,
- kZTag_Eacute,
- kZTag_Ecirc,
- kZTag_Egrave,
- kZTag_Euml,
- kZTag_Iacute,
- kZTag_Icirc,
- kZTag_Igrave,
- kZTag_Iuml,
- kZTag_Ntilde,
- kZTag_Oacute,
- kZTag_Ocirc,
- kZTag_Ograve,
- kZTag_Oslash,
- kZTag_Otilde,
- kZTag_Ouml,
- kZTag_Uacute,
- kZTag_Ucirc,
- kZTag_Ugrave,
- kZTag_Uuml,
- kZTag_aacute,
- kZTag_acirc,
- kZTag_aelig,
- kZTag_agrave,
- kZTag_amp,
- kZTag_aring,
- kZTag_atilde,
- kZTag_auml,
- kZTag_bdquo,
- kZTag_bull,
- kZTag_ccedil,
- kZTag_cent,
- kZTag_copy,
- kZTag_eacute,
- kZTag_ecirc,
- kZTag_egrave,
- kZTag_euml,
- kZTag_gt,
- kZTag_hellip,
- kZTag_iacute,
- kZTag_icirc,
- kZTag_iexcl,
- kZTag_igrave,
- kZTag_iquest,
- kZTag_iuml,
- kZTag_ldquo,
- kZTag_lsquo,
- kZTag_lt,
- kZTag_mdash,
- kZTag_micro,
- kZTag_nbsp,
- kZTag_ndash,
- kZTag_ntilde,
- kZTag_oacute,
- kZTag_ocirc,
- kZTag_ograve,
- kZTag_oslash,
- kZTag_otilde,
- kZTag_ouml,
- kZTag_para,
- kZTag_pi,
- kZTag_pound,
- kZTag_rdquo,
- kZTag_reg,
- kZTag_replace,
- kZTag_rsquo,
- kZTag_sbquo,
- kZTag_szlig,
- kZTag_trade,
- kZTag_uacute,
- kZTag_ucirc,
- kZTag_ugrave,
- kZTag_uuml,
- kZTag_yen,
- kZTag_yuml,
- kZTag_br
- };
-
-
- typedef struct ZStringParseInfo ZStringParseInfo;
-
- struct ZStringParseInfo
- {
- Z_Boolean fValidNamedString; // Is the string valid?
- const char * fNamedStringStart; // Start of entire named string
- const char * fNamedStringLimit; // Points one byte beyond the end
-
- const char * fNameStr; // Points to the path-delimited name of the string
- Z_UInt16 fNameStrLen; // Length of the path-delimited name
-
- Z_Boolean fHasMaxDataLen; // Data has a maximum length
- Z_UInt16 fMaxDataLen; // Maximum length of the data
-
- const char * fValueStr; // Points to the "prototype" of the string (including embedded tags)
- Z_UInt16 fValueStrLen; // Length of "prototype"
-
- Z_Boolean fIsVolatile; // Data pointed to are not to guaranteed to persist for the life of the program
- };
-
-
- /*==================================================================
- ZToolOptions
-
- This class groups the options that can be set for the ZStringTool.
- The default values are contained in the first constructor.
- ==================================================================*/
-
- class ZToolOptions
- {
- public:
- ZToolOptions();
- ZToolOptions(
- Z_Boolean inOutputNumeric,
- Z_Boolean inCategorizeOutput,
- Z_Boolean inAllowSemicolon,
- Z_Boolean inFlagDuplicates,
- Z_Boolean inOuputWarnings,
- Z_Boolean inConvertHighASCIIChar);
-
- Z_Boolean mOutputNumericTags; // The tags written are in numeric form (and not alphabetic).
- Z_Boolean mCategorizeOutput; // Output is grouped according to category (instead of strictly alphabetical).
- Z_Boolean mAllowTagSemicolon; // Semicolons are ignored at the end of alphabetic tags
- Z_Boolean mFlagDuplicates; // Duplicate ZStrings are indicated in the output
- Z_Boolean mHasOTags; // File contains O tags instead of Z tags (occurs when input file is a dictionary file - so that dict files can be compared)
- Z_Boolean mOutputWarnings; // Print warnings to the output file
- Z_Boolean mPrintErrorsOnly; // Only errors are printed to the output file (for reporting errors during the creation of the override dictionary)
- Z_Boolean mConvertHighASCIIChar; // Automatically convert high ascii characters to their html tags and produce a warning
- };
-
- typedef Z_UInt16 ZParserWarningType;
- enum {
- kZParser_NoWarnings = 0x0000, // No warnings
- kZParser_ChangedString = 0x0001, // A string has been modified because of a high ASCII character
- kZParser_FoundPossibleTag = 0x0002, // A possible tag has been found that is missing the &
- kZParser_HasHighASCII = 0x0004 // High ASCII characters still exist in the string
- };
-
- /*==================================================================
- ZStringParser
- ==================================================================*/
-
- class ZStringParser
- {
- public:
- enum
- {
- kTwoByteTableSize = 256
- };
-
- // Construction & Destruction
- ZStringParser();
-
- virtual
- ~ZStringParser()
- {
- check(sParser == this);
- sParser = 0L;
- }
-
- static ZStringParser &
- GetZStringParser()
- {
- check(sParser != NULL);
- return *sParser;
- }
-
- virtual void
- OverrideTwoByteTable(
- Z_UInt8 * inNewTable);
-
- static const char *
- SkipOverSpaces(
- const char * inCurrentPtr);
-
- static Z_Boolean
- ParseAdditionalParameters(
- const char * inCurrentPtr,
- ZStringParseInfo & outParseInfo);
-
- static Z_Boolean
- ParseNamedString(
- const char * inNamedString,
- ZStringParseInfo & outParseInfo,
- Z_Boolean inDataIsVolatile);
-
- virtual void
- CreateNewZString(
- const ZStringParseInfo & inParseInfo,
- ZString & outDestString);
-
- static ZStringTagID
- LookUpTagID(
- const char * inStartOfTag,
- const char * inStringLimit,
- Z_UInt16 & outTagNameLength);
-
- virtual Z_UInt16
- GetTagReplacement(
- ZStringTagID inTagID,
- char * outReplacement) = 0;
-
- static Z_UInt32
- ConvertTagIDToNumeric(
- ZStringTagID inTag);
-
- static const char *
- ConvertTagIDToString(
- ZStringTagID inTag);
-
- static Z_Boolean
- ConvertNamedStringToTag(
- const ZStringParseInfo & inParseInfo,
- const ZToolOptions & inOptions,
- ZString & outDestString,
- Z_UInt16 & outState);
-
- static Z_Boolean
- CheckDataLength(
- const ZStringParseInfo & inParseInfo);
-
- private:
- static Z_Boolean
- FindPossibleTag(
- const char * inCurInputPtr,
- const ZStringParseInfo & inParseInfo);
-
- static Z_SInt32
- CompareTagStrings(
- const char * inTagFromTable,
- const char * inParseString,
- const char * inParseStringLimit);
-
- static ZStringParser * sParser;
-
- Z_UInt8 mTwoByteTable[kTwoByteTableSize];
- };
-
-
- #endif // __ZSTRINGPARSER__
-
-
-